package com.amumu.drama.common.modules.order.service;

import com.amumu.drama.common.base.api.CommonPage;
import com.amumu.drama.common.modules.order.dto.ConfirmOrderResult;
import com.amumu.drama.common.modules.order.dto.GenerateOrderResult;
import com.amumu.drama.common.modules.order.dto.OmsOrderDetail;
import com.amumu.drama.common.modules.order.dto.OrderParam;
import com.amumu.drama.common.modules.order.dto.req.OrderQuery;
import com.amumu.drama.common.modules.order.dto.req.PayOrderReq;
import com.amumu.drama.common.modules.order.dto.req.ValidateInvitationCodeReq;
import com.amumu.drama.common.modules.order.dto.resp.MemberOrderListResp;
import com.amumu.drama.common.modules.order.dto.resp.ValidateInvitationCodeResp;
import com.amumu.drama.model.OmsOrder;
import com.amumu.drama.model.PmsProductTemplate;
import com.amumu.drama.model.PmsSkuStock;
import com.amumu.drama.model.UmsMember;
import com.baomidou.mybatisplus.extension.service.IService;
import org.springframework.transaction.annotation.Transactional;

import java.util.List;

/**
 * 前台订单管理Service
 * Created by macro on 2018/8/30.
 */
public interface OmsPortalOrderService extends IService<OmsOrder> {

    boolean queryFirstOrderStatus(UmsMember currentMember);

    ValidateInvitationCodeResp validateInvitationCode(ValidateInvitationCodeReq request, UmsMember currentMember);

    GenerateOrderResult generateOrder(OrderParam orderParam, UmsMember currentMember);

    @Transactional(rollbackFor = RuntimeException.class)
    OmsOrderDetail insertOrder(OrderParam orderParam, PmsProductTemplate productTemplate, PmsSkuStock skuStocks, UmsMember currentMember, ValidateInvitationCodeResp invitationCodeResp);

    CommonPage<MemberOrderListResp> queryOrderList(OrderQuery request, UmsMember currentMember);

    OmsOrderDetail detail(Long orderId);

    CommonPage<OmsOrderDetail> list(String status, Integer pageNum, Integer pageSize, UmsMember currentMember);


    GenerateOrderResult payOrder(PayOrderReq request, UmsMember currentMember);

    @Transactional
    void cancelOrder(Long orderId, UmsMember currentMember);

    /**
     * 根据用户购物车信息生成确认单信息
     */
    ConfirmOrderResult generateConfirmOrder(List<Long> cartIds, UmsMember currentMember);

    /**
     * 支付成功后的回调
     */
    @Transactional
    Integer paySuccess(Long orderId, Integer payType);

    Integer paySuccessUpdate(Long orderId, Integer payType);

    /**
     * 自动取消超时订单
     */
    @Transactional
    Integer cancelTimeOutOrder();


    /**
     * 发送延迟消息取消订单
     */
    void sendDelayMessageCancelOrder(Long orderId);

    /**
     * 确认收货
     */
    void confirmReceiveOrder(Long orderId, UmsMember currentMember);

    OmsOrder queryOrderByOrderId(Long orderId);

    /**
     * 根据订单编号查询订单详情
     *
     * @param orderSn
     * @return
     */
    OmsOrder queryOrderByOrderSn(String orderSn);

    /**
     * 用户根据订单ID删除订单
     */
    void deleteOrder(Long orderId, UmsMember currentMember);

    @Transactional
    void paySuccessByOrderSn(String orderSn, Integer payType);

    Long getCodeCount(Long code);

    /** 查询用户订单详情 */
    MemberOrderListResp orderDetail(Long orderId);
}
